package logic

import (
	"bawei_2112a_shop/order-srv/order"
	"context"

	"bawei_2112a_shop/api/internal/svc"
	"bawei_2112a_shop/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GenerateOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGenerateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateOrderLogic {
	return &GenerateOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GenerateOrderLogic) GenerateOrder(req *types.GenerateOrderrequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.OrderSrv.GenerateOrder(l.ctx, &order.GenerateOrderRequest{
		UserId:  1, // 汪超完成
		GoodsId: req.GoodsId,
		Count:   int32(req.Count),
		PayType: int32(req.PayType),
	})

	if err != nil {
		return &types.Response{
			Code:    -1,
			Message: err.Error(),
		}, nil
	}
	return &types.Response{
		Code:    0,
		Message: "success",
		Data: map[string]interface{}{
			"order_id": res.OrderId,
		},
	}, nil
}
